package cn.changshengjue.dakong.command.sub;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import cn.changshengjue.dakong.main;
import cn.changshengjue.dakong.api.apiImpl;
import cn.changshengjue.dakong.command.SubCommand;
import cn.changshengjue.dakong.command.type.AdminCommand;
import cn.changshengjue.dakong.config.cfg;
import cn.changshengjue.dakong.utils.ItemSerialize;
import cn.changshengjue.dakong.utils.Utils;
import cn.changshengjue.dakong.utils.YmlUtil;

public class GiveCommand extends SubCommand implements AdminCommand {
	public GiveCommand() {
		super("give", "/dk give [player] [id] [amount]", main.getInstance().getConfig().getString("commands.give"));
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

		
		Player player = Bukkit.getPlayer(args[1]);
		ItemStack fb = new apiImpl().getFB(args[2]);
		if (Utils.itemIsAIR(fb)) {
			sender.sendMessage(cfg.MSG_PLUGIN+cfg.MSG_GIVE_3.replace("%id%", args[2]));
			return false;
		}
		if (player ==null) {
			sender.sendMessage(cfg.MSG_PLUGIN+cfg.MSG_GIVE_4.replace("%player%", args[1]));
			return false;
		}
		if (player.isOnline()==false) {
			sender.sendMessage(cfg.MSG_PLUGIN+cfg.MSG_GIVE_4.replace("%player%", args[1]));
			return false;
		}
		fb.setAmount(Integer.valueOf(args[3]));
		player.getInventory().addItem(fb);
		sender.sendMessage(cfg.MSG_PLUGIN+cfg.MSG_GIVE_1.replace("%player%", args[1]).replace("%item%", fb.getItemMeta().getDisplayName()).replace("%amount%", args[3]));
		player.sendMessage(cfg.MSG_PLUGIN+cfg.MSG_GIVE_2.replace("%player%", sender.getName()).replace("%item%", fb.getItemMeta().getDisplayName()).replace("%amount%", args[3]));
		return false;
	}

	@Override
	public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
		return null;
	}

}
